#include "chatbuf.h"
#include <QDebug>
//会话号 内容  对象
//注意，可以存储多个会话的新消息

ChatBuf* ChatBuf::chatbuf=nullptr;
ChatBuf *ChatBuf::getInstance()
{
    if(chatbuf==nullptr)
    {
        chatbuf=new ChatBuf;
    }
    return chatbuf;
}

QList<QPair<QPair<QString,QString>,bool>> ChatBuf::getList()
{
    return chatlist;
}

void ChatBuf::addChat(QString chatoc,QString content,bool sender)
{
    qDebug()<<"add ChatBuf"<<chatoc<<content<<sender;
    chatlist.append(QPair<QPair<QString,QString>,bool>(QPair<QString,QString>(chatoc,content),sender));
}


void ChatBuf::clear()
{
    if(!chatlist.isEmpty())
        chatlist.clear();
}

bool ChatBuf::isEmpty()
{
    return chatlist.isEmpty();
}

void ChatBuf::freshNow()
{
    if(!chatlist.isEmpty())
        emit s_chatListWrite(chatlist);

}

ChatBuf::ChatBuf(){}

